package reflect;

import java.lang.reflect.Field;

/**
 * 使用反射机制直接操作属性
 *
 */
public class ReflectDemo8 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Teacher t = new Teacher();
        t.name="张三";
        System.out.println(t);

        Class cls = Class.forName("reflect.Person");
        Object object = cls.newInstance();
        Field field = cls.getDeclaredField("name");
        field.set(object,"李四");
        System.out.println(object);
    }
}
